﻿using System.Runtime.Serialization;
using Game.Common;
using Game.Common.Resources;

namespace Game.Types
{
    [DataContract(Namespace="game")]
    public class BuildingType : ContainerBaseType
    {
        ReadonlyGameResources _Tank;

        internal BuildingType()
        {
        }
        
        public BuildingType(BuildingTypeBuilder builder)
            : base(builder)
        {
            _Tank = builder.Tank.GetReadOnly();
        }

        [OnDeserialized]
        public void OnDeserialized2(StreamingContext c)
        {
            object obj = ResourceLocator.GameResourceLocator.Get(Url);
            var t = obj as BuildingType;
            if (t != null)
            {
                _Tank = t.Tank;
            }
        }

        public ReadonlyGameResources Tank
        {
            get { return _Tank; }
        }

    }

#region "Builder"
    public class BuildingTypeBuilder : ContainerBaseTypeBuilder
    {
        GameResources _Tank = new GameResources();

        public BuildingType BuildBuildingType()
        {
            return new BuildingType(this);
        }
        
        public override string TypeName 
        {
            get { return "building"; }
        }

        public GameResources Tank
        {
            get { return _Tank; }
            set { _Tank = value; }
        }

    }
#endregion

}
